package module.building.view.buildingListPanel
{
	import com.darwin.darwinUI.assist.IGroupItem;
	import com.darwin.darwinUI.controls.Label;
	import com.darwin.darwinUI.controls.TabPanelBase;
	
	public class BuildTabPanel extends TabPanelBase
	{
		private var _sourceArray:Array;
		private var _list:BuildList;
		private var _listChanged:Boolean;
		private var _selectedType:String;
		private var _label:Label;
		
		public function BuildTabPanel(data:Array)
		{
			super();
			_sourceArray = data;
			_list = new BuildList();
			_label = new Label("aaaaaaaaaa");
			_label.autoSize = true;
			_label.x = 226;
			_label.y = 389;
			addChild(_list);
			addChild(_label);
		}
		
		/**
		 *  根据选中项刷新显示内容 
		 */
		public function update():void
		{
			var array:Array = _sourceArray;		
			if(array)
			{
				var source:Array = array.filter(isSelected);
				_list.source = source;
				refreshPageLabel();
			}
			//			var source:Array = array;
		}
		
		/**
		 * 当选项卡组中的被选中项发生改变时，
		 * @param tab
		 */
		override public function tabSelectionChange(tab:IGroupItem):void
		{
			_selectedType = (tab as SubBuildTab).subType;
			trace("tab"+(tab as SubBuildTab).subType);
			update();
		}
		
		private function refreshPageLabel():void
		{
			if(list.pageLength > 0)
			{
				_label.text = list.currentPage+1+"/"+list.pageLength;				
			}
			else
			{
				_label.text = "0/0";
			}
			trace(_label.text);
		}
		
		private function isSelected(element:*, index:int, arr:Array):Boolean
		{
			if(_selectedType.length == 1)
			{
				return (element.buildingObj.type == _selectedType);
			}else
			{
				return (element.buildingObj.subType == _selectedType);
			}
			
		}
		
		public function get list():BuildList
		{
			return _list;
		}

		public function get sourceArray():Array
		{
			return _sourceArray;
		}

		public function set sourceArray(value:Array):void
		{
			_sourceArray = value;
			update();
		}

	}
}